#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>

int test_file;
const char *path = "/dev/led_button_driver";

int main(int argc, char *argv[]) {
  int num;
  
  if(argc >= 2){
    num = atoi(argv[1]);
  }else {
    num = 3;
  }

  errno = 0;
  test_file = open(path,O_RDWR);
  write(test_file,&num,sizeof(num));
  if(test_file == -1){
    printf("device could not be opened");
    fprintf(stderr,"error: %s.\n",strerror(errno));
    return -1;
  }

  while(1){
    read(test_file,&num, sizeof(num));
    if(num != 0){
      printf("pressed button: %d",num);
    }
    if(num == 0x80)
      break;
  }
  
  if(close(test_file)){
    printf("error: in fclose");
  }else{
    printf("file closed");
  }

  return 0;
}
